package cn.yj.syslog.controller;


import cn.yj.annotation.pagehelper.PageBaseController;
import cn.yj.annotation.pagehelper.page.OrderBy;
import cn.yj.annotation.pagehelper.page.Page;
import cn.yj.commons.utils.StringUtils;
import cn.yj.entity.R;
import cn.yj.syslog.common.LogType;
import cn.yj.syslog.entity.SysLog;
import cn.yj.syslog.service.ISysLogService;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 永健
 * @since 2019-12-01 20:36
 */
@RestController
@RequestMapping("/sysLog")
@Configuration
public class SysLogController implements PageBaseController<SysLog> {

    @Resource
    ISysLogService thisService;


    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> sysLog) {
        Page<SysLog> page = thisService.findList(sysLog, page(new OrderBy(OrderBy.Direction.DESC, "create_time")));

        List<SysLog> rows = page.getRows();
        rows.forEach(log -> {
            String operateType = log.getOperateType();
            if (StringUtils.isBlank(operateType)) {
                log.setOperateType("其它");
                return;
            }
            LogType[] values = LogType.values();
            for (int i = 0; i < values.length; i++) {
                LogType value = values[i];
                if (value.name().equals(operateType)) {
                    log.setOperateType(value.getDesrc());
                }
            }
        });
        return R.success(page);
    }

}

